package com.atguigu.gmall.product.controller;

import com.atguigu.gmall.common.result.Result;
import com.atguigu.gmall.model.product.SpuInfo;
import com.atguigu.gmall.product.service.ManageService;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/admin/product")
public class SpuManageController {

    @Autowired
    private ManageService manageService;

    //spu分页列表
    @GetMapping("{page}/{limit}")
    public Result getSpiInfoList(@PathVariable long page,
                                 @PathVariable long limit,
                                 SpuInfo spuInfo){
        Page<SpuInfo> page1 = new Page(page, limit);
        IPage<SpuInfo> spuInfoIList= manageService.getSpiInfoList(page1,spuInfo);

        return  Result.ok(spuInfoIList);
    }


    //保存spu
    @PostMapping("saveSpuInfo")
    public Result saveSpuInfo(@RequestBody SpuInfo spuInfo){
        manageService.saveSpuInfo(spuInfo);
        return Result.ok();
    }


}
